package com.cc.blog.controller;

import com.cc.blog.common.aop.Cache;
import com.cc.blog.common.aop.LogAnnotation;
import com.cc.blog.service.ArticleService;
import com.cc.blog.vo.params.ArticleParam;
import com.cc.blog.vo.params.PageParams;
import com.cc.blog.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/articles")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 首页文章列表
     * @param pageParams
     * @return
     */
    @PostMapping
    @LogAnnotation(module = "文章",operation = "获取文章列表")
    @Cache(expire = 5 * 60 * 1000,name = "articles")
    public Result articles(@RequestBody PageParams pageParams){
        return articleService.articeList(pageParams);
    }

    /**
     * 首页最热文章
     * @return
     */

    @PostMapping("/hot")
    public Result hotArticle(){
        int limit = 5;
        return articleService.hotArtice(limit);
    }

    /**
     * 首页最新文章
     * @return
     */
    @PostMapping("/new")
    public Result newArticle(){
        int limit = 5;
        return articleService.newArticle(limit);
    }

    @PostMapping("/listArchives")
    public Result listArchives(){
        return articleService.listArchives();
    }

    @PostMapping("/view/{id}")
    public Result findArticleById(@PathVariable("id") Long id){
        return articleService.findArticleById(id);
    }

    @PostMapping("/publish")
    public Result publish(@RequestBody ArticleParam articleParam){
        return articleService.publish(articleParam);
    }

}
